/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package buzzerproxy; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.ArrayList; import org.apache.http.client.ClientProtocolException; /** * * @author Enger */ public class GoogleResultParser { public ArrayList parseResults(String rawResults, String filetyp ) { if (rawResults == null || filetyp == null ) { Exception e = new Exception(); Logger.getLogger(GoogleResultParser.class.getName()).log(Level.SEVERE, null, e); System.exit(1); } // if ( str == null || !(str instanceof String)){ Http h = new Http(); StringBuilder sb = new StringBuilder(); String[] arr = rawResults.split("\""); boolean isAlive = false; // sb.append(""); // sb.append(""); // sb.append("Results"); try { for (int i = 0; i < arr.length; i++) { int pos = i + 2; if (arr[i].equalsIgnoreCase("unescapedUrl")) { String url = arr[pos]; CheckStatus status = new CheckStatus(); System.out.println("Found result Url: " + url); try { isAlive = status.isAlive(url); } catch (ClientProtocolException ex) { Logger.getLogger(GoogleResultParser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GoogleResultParser.class.getName()).log(Level.SEVERE, null, ex); } // System.out.println("URL: " + url + " Status: " + isAlive[0]); if (isAlive) { try { ArrayList results = h.extractLinks(url); // for (String urltocheck : results) { // System.out.println("\t Ergebnisurl wird nun gechecked: " + urltocheck); // } h.prepareParallelCheck(results, filetyp, h); } catch (IOException ex) { // Logger.getLogger(GoogleResultParser.class.getName()).log(Level.SEVERE, null, ex); } catch ( Exception e){ } } // if (isAlive){ } // if (arr[i].equalsIgnoreCase("unescapedUrl")) { } // for (int i = 0; i < arr.length; i++) { } catch (ArrayIndexOutOfBoundsException a) { Logger.getLogger(GoogleResultParser.class.getName()).log(Level.SEVERE, null, a); } // sb.append(""); // sb.append(""); ArrayList cont = h.getValidResults(); return cont; } // public String parseResults(String rawResults) { //// public static void main(String[] args) { //// //// String file = new String("G:\\results.txt"); //// String fileContent = ""; //// try { //// fileContent = Gzip.readFileAsString(file); //// } catch (IOException ex) { //// Logger.getLogger(GoogleResultParser.class.getName()).log(Level.SEVERE, null, ex); //// } //// System.out.println(parseResults(fileContent)); //// //// //// } // System.out.println("array"+i+" :"+arr[i]); //titleNoFormatting unescapedUrl // if (arr[i].equalsIgnoreCase("titleNoFormatting")) { // sb.append(""); // sb.append(arr[pos]); // sb.append(""); // } // // if (arr[i].equalsIgnoreCase("unescapedUrl")) { // sb.append(""); // sb.append(arr[pos]); // // sb.append(""); // System.out.println("REAL POSITION: '" + arr[i] + "'"); // System.out.println("ARRAY PèOSTITION: " + arr[pos]); } // public class GoogleResultParser {